package cn.edu.hy.demo06.controller;

import cn.edu.hy.demo06.entity.Teacher;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;

@Controller
@RequestMapping("teacher")
public class TeacherController {


    @GetMapping("index")
    public String index(Model model){
        model.addAttribute("list",getTeachers());
        return "demo06/teacherIndex";
    }

    @RequestMapping(value = "getList",method = RequestMethod.POST)
    @ResponseBody
    public List<Teacher> getList(){


        List<Teacher> list = getTeachers();

        return list;

    }

    private static List<Teacher> getTeachers() {
        List<Teacher> list = new ArrayList<Teacher>();
        Teacher teacher1 = new Teacher("张老师","语文",20);
        Teacher teacher2 = new Teacher("王老师","数学",20);
        Teacher teacher3 = new Teacher("李老师","英文",20);
        list.add(teacher1);
        list.add(teacher2);
        list.add(teacher3);
        return list;
    }
}
